cmake_minimum_required(VERSION 2.8)

###########################
## SET PROJECT VARIABLES ##
###########################

# If flex and bison are installed in ~/local the following lines are needed.
set(CMAKE_PREFIX_PATH  ${CMAKE_PREFIX_PATH}  "~/local")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "~/local/lib")
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "~/local/include")

# Where the resulting files will spawn.
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
set(LIBRARY_OUTPUT_PATH    "${CMAKE_SOURCE_DIR}/lib")

# Build type:
# - None
# - Debug
# - Release
# - RelWithDebInfo
# - MinSizeRel
set(CMAKE_BUILD_TYPE Debug)

# The main include directory of the project.
include_directories("${CMAKE_SOURCE_DIR}/include")

# Add some global flags.
add_definitions(-std=gnu++11 -Wno-deprecated-declarations -Wall)

########################
## USE BISON AND FLEX ##
########################

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

include_directories(${FLEX_INCLUDE_DIRS})

bison_target(parser "./SimpleC.yy" "${CMAKE_CURRENT_BINARY_DIR}/SimpleC_gram.cpp"
  COMPILE_FLAGS "--debug -Wno-conflicts-sr")
flex_target(scanner "./SimpleC.lex" "${CMAKE_CURRENT_BINARY_DIR}/SimpleC_lex.cpp")
add_flex_bison_dependency(scanner parser)

########################
## GENERATE EXECUTABLE #
########################

file(GLOB SOURCE
  "*.cpp"
  "*/*.cpp")
file(GLOB HEADER
  "*.h*"
  "*/*.h")

add_executable(my_comp
  ${HEADER} ${SOURCE}
  ${BISON_parser_OUTPUTS} ${FLEX_scanner_OUTPUTS})
target_link_libraries(my_comp ${FLEX_LIBRARIES})

